//
//  LivingRoad.m
//  EquiriesProject
//
//  Created by qianfeng on 15/10/29.
//  Copyright (c) 2015年 HXH. All rights reserved.
//

#import "LivingRoad.h"

@interface LivingRoad ()<BMKMapViewDelegate,BMKLocationServiceDelegate>

@end

@implementation LivingRoad
{
    BMKMapView * _mapView;
    BMKAnnotationView * _annotionView;
    BMKLocationService * _locationDervice;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatNav];
    [self makeMap];
}

-(void)makeMap
{
    _mapView = [[BMKMapView alloc]initWithFrame:CGRectMake(0, 64, Width, Height)];
    _mapView.delegate = self;
    _mapView.mapType = 0;
    //显示位置
    _mapView.showsUserLocation = YES;
    
    //跟着模式
    _mapView.userTrackingMode = BMKUserTrackingModeFollowWithHeading;
    [self.view addSubview:_mapView];
    
    BMKPointAnnotation * pointAnnotation = [[BMKPointAnnotation alloc]init];
    pointAnnotation.coordinate = CLLocationCoordinate2DMake(39.905,116.44);
    pointAnnotation.title = @"北京";
    [_mapView addAnnotation:pointAnnotation];
    
    for (int i=0; i<3; i++) {
        NSArray * a0 = @[@"39.905",@"40.130762053452",@"40.132016329827"];
        NSArray * a2 = @[@"116.44",@"116.27784197194",@"116.27534213863"];
        BMKPointAnnotation * pointAnnotation = [[BMKPointAnnotation alloc]init];
        pointAnnotation.coordinate = CLLocationCoordinate2DMake([a0[i] intValue],[a2[i] intValue]);
        pointAnnotation.title = @"北京";
        [_mapView addAnnotation:pointAnnotation];
    }
}

-(void)creatNav
{
    UINavigationBar * bar=self.navigationController.navigationBar;
    [bar setBackgroundImage:[UIImage imageNamed:@"custom_dialog_btn_bg"] forBarMetrics:UIBarMetricsDefault];
    [self.view addSubview:bar];
    
    UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 30)];
    [button setImage:[UIImage imageNamed:@"back_press"] forState:UIControlStateNormal];
    [self.view addSubview:button];
    UIBarButtonItem * item = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = item;
    
    [button addTarget:self action:@selector(ReturnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 40)];
    label.text = @"违章高发地";
    label.textColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    self.navigationItem.titleView = label;
    
    UIButton * btn1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    [btn1 setBackgroundImage:[UIImage imageNamed:@"back_press"] forState:UIControlStateNormal];
    [self.view addSubview:btn1];
    UIButton * btn2 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    [btn2 setBackgroundImage:[UIImage imageNamed:@"back_press"] forState:UIControlStateNormal];
    [self.view addSubview:btn2];
    UIBarButtonItem * item1 = [[UIBarButtonItem alloc]initWithCustomView:btn1];
    UIBarButtonItem * item2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
    NSArray * a1 = @[item1,item2];
    self.navigationItem.rightBarButtonItems = a1;
    [btn1 addTarget:self action:@selector(btnItemClick) forControlEvents:UIControlEventTouchUpInside];
    [btn2 addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)ReturnClick
{
    NSArray * a1 = self.navigationController.viewControllers;
    
    [self.navigationController popToViewController:a1[0] animated:YES];
}

-(void)btnItemClick
{
    
}

-(void)btnClick
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
